package com.mycity.services;

import java.util.List;

import com.mycity.bean.Post;
import com.mycity.dao.PostDao;
import com.mycity.util.TagUtil;

public class SearchService {
	
	PostDao postDao = new PostDao();
	
	public List<Post> searchByTag(String tag){
		List<Post> postList = postDao.getPostsByTag(tag);
		setTags(postList);
		return postList;
		
	}
	
	public List<Post> searchByLocation(int locationId){
		List<Post> postList = postDao.getPostsByLocation(locationId);
		setTags(postList);
		return postList;
		
	}
	
	private void setTags(List<Post> posts){
		for(int i=0; i<posts.size(); i++){
			String[] tagList = postDao.getTagsByPostId(posts.get(i).getPostId());
			posts.get(i).setTags(TagUtil.generate(tagList));
		}

	}

}
